"""
Author        yongfa
Date          2022-07-11 14:48:04
LastEditTime  2023-07-07 17:36:43
LastEditors   yongfa
Description   请求参数
"""

from flask_restx import reqparse, inputs
from app.extensions.utils.enums import UserEnum, LoginTypeEnum
from app.extensions.utils.parameters import page_params


# get 方法获取参数 必须写location=arg
get_list_params = page_params.copy()
get_list_params.add_argument('username', type=str, trim=True, location='args', help='用户名')
get_list_params.add_argument('email', type=str, location='args', trim=True, help='邮箱')
get_list_params.add_argument('mobile', type=str, location='args', help='手机号码')
get_list_params.add_argument('language', type=str, location='args', trim=True, help='语言')


# 创建
create_params = reqparse.RequestParser()
create_params.add_argument('username', trim=True, required=True, location='json', help='用户名')
create_params.add_argument('password', type=str, trim=True, required=True, location='json', help='密码')
create_params.add_argument('email', type=str, trim=True, location='json', help='邮箱')
create_params.add_argument('mobile', type=inputs.regex(
    "1[3|4|5|7|8|9][0-9]{9}"), trim=True, location='json', help='手机号码')
create_params.add_argument('avatar', type=str, trim=True, location='json', help='头像')
create_params.add_argument('auth', type=int, choices=UserEnum.list_values(), location='json', help='类型')
create_params.add_argument('role_ids', type=list, location='json', help='角色列表')
create_params.add_argument('language', type=str, location='json', help='语言')
create_params.add_argument('extend', type=str, location='json', help='备注')
create_params.add_argument('address', type=str, location='json', help='地址')


# 修改
update_params = create_params.copy()
update_params.replace_argument('username', trim=True, location='json', help='用户名')
update_params.replace_argument('password', trim=True, location='json', help='密钥')


# 用户修改
user_update_params = reqparse.RequestParser()
user_update_params.add_argument('email', type=inputs.regex(inputs.email_regex), trim=True, location='json', help='邮箱')
user_update_params.add_argument('mobile', type=inputs.regex(
    "1[3|4|5|7|8|9][0-9]{9}"), trim=True, location='json', help='手机号码')
user_update_params.add_argument('avatar', type=str, trim=True, location='json', help='头像')
user_update_params.add_argument('language', type=str, location='json', help='语言')
user_update_params.add_argument('extend', type=str, location='json', help='备注')
user_update_params.add_argument('address', type=str, location='json', help='地址')

# 修改密码

user_password_update_params = reqparse.RequestParser()
user_password_update_params.add_argument('old_password', type=str, trim=True, location='json', help='旧密码')
user_password_update_params.add_argument('new_password', type=str, trim=True, location='json', help='新密码')


# 登录
login_params = reqparse.RequestParser()
login_params.add_argument('username', type=str, trim=True, required=True, location='json', help='用户名')
login_params.add_argument('password', type=str, trim=True, required=True, location='json', help='密码')
login_params.add_argument('auth', type=int, location='json', help='类型')
login_params.add_argument('login_type', type=int, choices=LoginTypeEnum.list_values(),
                          default=LoginTypeEnum.PASSWORD.value, location='json', help='登录类型')


params_dict = {
    "get_list_params": get_list_params,
    "create_params": create_params,
    "update_params": update_params,
    "user_update_params": user_update_params,
    "user_password_update_params": user_password_update_params,
    "login_params": login_params
}
